#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""使用requests请求代理服务器
请求http和https网页均适用
"""
import requests

import requests


# 1. 先请求获取可用IP
res = requests.get("https://dps.kdlapi.com/api/getdps/?secret_id=?&signature=?&num=1&pt=1&format=text&sep=1")
# text 或者json 取决于服务器返回类型
ip_port = res.text

# 2. 构造proxies参数 发起请求
username = 'd4128411536'
password = 'njyzbgtb'

proxies = {
    "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {'user': username, 'pwd': password, 'proxy': ip_port},
    "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {'user': username, 'pwd': password, 'proxy': ip_port}
}

res = requests.get("http://httpbin.org/get", proxies=proxies)
print(f"IP: {res.json()['origin']}")